// fire_alarm_alert.dart
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rjpb/page/home/fireAlarmAlert/controller/fire_alarm_alert_controller.dart';

class FireAlarmAlert extends StatelessWidget {
  const FireAlarmAlert({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final controller = Get.find<FireAlarmAlertController>();

    return Obx(() {
      if (!controller.isShowing) return const SizedBox.shrink();

      return Stack(
        children: [
          // 半透明蒙层
          GestureDetector(
            onTap: () => controller.dismissAlert(),
            child: Container(
              color: Colors.black54,
              width: double.infinity,
              height: double.infinity,
            ),
          ),

          // 弹窗内容
          Center(
            child: Material(
              borderRadius: BorderRadius.circular(16),
              color: Colors.white,
              elevation: 8,
              child: Container(
                width: MediaQuery.of(context).size.width * 0.8,
                padding: const EdgeInsets.all(20),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    // 标题和关闭按钮
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Text(
                          '火警警报',
                          style: TextStyle(
                            fontSize: 20,
                            fontWeight: FontWeight.bold,
                            color: Colors.red,
                          ),
                        ),
                        IconButton(
                          icon: const Icon(Icons.close, color: Colors.grey),
                          onPressed: () => controller.dismissAlert(),
                        ),
                      ],
                    ),

                    const SizedBox(height: 16),

                    // 警报图标和消息
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        const Icon(Icons.warning, color: Colors.red, size: 40),
                        const SizedBox(width: 16),
                        Expanded(
                          child: Text(
                            controller.alertMessage,
                            style: const TextStyle(
                              fontSize: 16,
                              color: Colors.black87,
                            ),
                          ),
                        ),
                      ],
                    ),

                    const SizedBox(height: 24),

                    // 按钮区域
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: [
                        // 消音按钮
                        ElevatedButton(
                          style: ElevatedButton.styleFrom(
                            backgroundColor: Colors.orange,
                            padding: const EdgeInsets.symmetric(
                                horizontal: 24, vertical: 12),
                            shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(8),
                            ),
                          ),
                          onPressed: () => controller.muteAlarm(),
                          child: const Text(
                            '消音',
                            style: TextStyle(
                              fontSize: 16,
                              color: Colors.white,
                            ),
                          ),
                        ),

                        // 查看详情按钮
                        ElevatedButton(
                          style: ElevatedButton.styleFrom(
                            backgroundColor: Colors.red,
                            padding: const EdgeInsets.symmetric(
                                horizontal: 24, vertical: 12),
                            shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(8),
                            ),
                          ),
                          onPressed: () => controller.viewDetails(),
                          child: const Text(
                            '查看详情',
                            style: TextStyle(
                              fontSize: 16,
                              color: Colors.white,
                            ),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ),
          ),
        ],
      );
    });
  }
}
